14、批量物料编号在mysql数据库查询
from sqlalchemy import create_engine, text
import pandas as pd
# 创建数据库连接
engine = create_engine('mysql+mysqlconnector://root:502@localhost:3306/shn')
current_parents=["12613010","1272-141-22-1"] #这个用df会出错
print(current_parents)
def fetch_sa_data():
# 执行数据库查询
query = f"""
SELECT *
FROM ct
WHERE `ct_ItemRelation` IN ({','.join([f"'{x}'" for x in current_parents])})
and `ct_mobileType` = "销售订单"
"""
chunk = pd.read_sql(query, engine)
return chunk
dfs_sa =fetch_sa_data()
print(dfs_sa)
返回:
['12613010', '1272-141-22-1']
ct_mobileType | ct_PO | ... | ct_affiliatedGroupCustomers | ct_productNumber | |
0 | 销售订单 | S1904237699 | ... | 深圳市金洋电子股份有限公司 | 12613010 |
1 | 销售订单 | S1905240502 | ... | 深圳市金洋电子股份有限公司 | 12613010 |
12613010 | |||||
... | ... | ... | ... | ... | ... |
2256 | 销售订单 | S2501221962 | ... | 阳光电源 | 12613010 |
2257 | 销售订单 | S2502223887 | ... | 思格 | 12613010 |
[2258 rows x 28 columns]